package club.adger.controller;

import club.adger.util.ConstantWeChatUtils;
import org.apache.http.client.utils.HttpClientUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Adger
 * @Date: 2020/12/11/23:22
 */
@CrossOrigin
@Controller
@RequestMapping(value = "/wechat")
public class WeChatLoginController {
    //1 生成微信扫描二维码
    @GetMapping("login")
    public String getWxCode() {
        //固定地址，后面拼接参数
        String url = "https://open.weixin.qq.com/connect/qrconnect?appid=wxed9954c01bb89b47&redirect_uri=http://guli.shop/api/ucenter/wx/callback&response_type=code&scope=snsapi_login&state=%s#wechat_redirect";
        //对redirect_url进行URLEncoder编码
        String redirectUrl = ConstantWeChatUtils.WX_OPEN_REDIRECT_URL;
        try {
            redirectUrl = URLEncoder.encode(redirectUrl, "utf-8");
        }catch(Exception e) {
        }
        //重定向到请求微信地址里面
        return "redirect:"+url;
    }
}

